const tagArray = ["理想主义青年", "双重人格的", "颜控", "义气虾", "颜控", "的", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "的", "吊炸天的", "mmp的", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "的", "牛皮的", "吊炸天的", "mmp的"]
var util = require('../../../../../utils/util.js')
var _this
const app = getApp()
Page({
  data: {
    initTagSelectedArray: [],
    initCustomTagSelectedArray: [],
    cutsomTag1: '',
    cutsomTag2: '',
    cutsomTag3: '',
    apiType: 1,
    tagSelectedArray: [],
    customTagSelectedArray: [],
    title: '添加自己性格标签',
    subtitle: '我是不一样的烟火'
  },
  onLoad: function (options) {
    _this = this
    let data = JSON.parse(options.value).split(',')
    let apiType = Number(options.apiType)
    let customTag = options.customtag == 'null' ? [] : options.customtag.split(',')
    let array = []
    for (let i = 0; i < data.length; i++) {
      array.push(data[i])
    }
    _this.setData({
      initTagSelectedArray: array,
      apiType: apiType,
      initCustomTagSelectedArray: customTag
    })
    if (apiType == 3) {
      _this.setData({
        title: '添加匹配对象标签',
        subtitle: '对象的这些标签正中我胃口'
      })
    }
  },
  tagSelectedFinishedHandle: function (e) {
    console.log(e.detail)
    _this.setData({
      tagSelectedArray: e.detail.tagSelectedArray,
      customTagSelectedArray: e.detail.customTagSelectedArray
    })
    //标签已经选择完毕，可以继续下一把
    _this.updateUserInfo()
  },
  updateUserInfo: function () {
    var data = {}
    switch (_this.data.apiType) { 
      case 1: 
        data.labels2 = _this.data.tagSelectedArray.join()
        if (_this.data.customTagSelectedArray.length > 0) {
          data.otherLabels2 = _this.data.customTagSelectedArray.join()
        }
        break
      case 3: 
        data.labels = _this.data.tagSelectedArray.join()
        // if (_this.data.customTagSelectedArray.length > 0) {
        //   data.otherLabels = _this.data.customTagSelectedArray.join()
        // }
        break
    }
    util.updateUserInfo(_this.requestDidResponse, _this.requestDidFaild, data)
    wx.showLoading({
      title: '资料保存中...',
    })
  },
  requestDidResponse: (res) => {
    if (res.status == '200') {
      wx.navigateBack({
        delta: 1
      })
    } else {
      wx.showToast({
        title: '保存失败，请重试',
        icon: 'none'
      })
    }
  },
  requestDidFaild: (res) => {
    wx.showToast({
      title: '网络走神了，请稍候再试哦',
      icon: 'none'
    })
  },
  customTagDidClick: function () {
    wx.navigateTo({
      url: '../../infoTagCustom/infoTagCustom',
    })
  },
  addTag: (tag) => {
    console.log(tag)
    _this.setData({
      cutsomTag: tag
    })
    if (_this.data.apiType == 1) {
      _this.setData({
        cutsomTag1: tag
      })
    } else {
      // _this.setData({
      //   cutsomTag3: tag
      // })
    }
  },
})